window.tywx || (window.tywx = {}),
    tywx.OpenDataContextUtil = {
        methodIndex: 0,
        methodCallDic: {},
        isOnTimer: !1,
        initCheckTimer: function () {
            if (!this.isOnTimer) {
                this.isOnTimer = !0;
                tywx.Timer.setTimer(cc.director, function () {
                    tywx.OpenDataContextUtil.checkOpenDataContextStat();
                }, .1, cc.macro.REPEAT_FOREVER, 0);
            }
        },
        checkOpenDataContextStat: function () {
            var e = wx.getOpenDataContext().canvas.getContext("2d");
            for (var t in this.methodCallDic) tywx.LOGD("开始检查:" + t, "abcd"), e[t] ? (1 == e[t].status ? (tywx.LOGD("success_callback:" + t, JSON.stringify(e[t])),
            this.methodCallDic[t].success_callback && this.methodCallDic[t].success_callback(e[t].data),
                tywx.NotificationCenter.trigger(tywx.EventType.GET_OPEN_DATA_RESULT_SUCCESS, [t, e[t].data])) : (tywx.LOGD("success_callback:" + t, JSON.stringify(e[t])),
            this.methodCallDic[t].fail_callback && this.methodCallDic[t].fail_callback(e[t].data),
                tywx.NotificationCenter.trigger(tywx.EventType.GET_OPEN_DATA_RESULT_FAIL, [t, e[t].data])),
                delete e[t], delete this.methodCallDic[t]) : new Date().valueOf() - this.methodCallDic[t].time > 2 && (tywx.NotificationCenter.trigger(tywx.EventType.GET_OPEN_DATA_RESULT_TIMEOUT, [t]),
                delete e[t], delete this.methodCallDic[t]);
        },
        getUserInfo: function (e, t) {
            var n = "getUserInfo" + this.methodIndex;
            return wx.getOpenDataContext().postMessage({
                method: "getUserInfo",
                data: {
                    method_id: n
                }
            }), this.methodIndex++, this.methodCallDic[n] = {
                time: new Date().valueOf(),
                success_callback: e,
                fail_callback: t
            }, n;
        },
        updateRankData: function (e) {
            var t = "updateRankData" + this.methodIndex, n = [];
            for (var o in e) {
                var i = {
                    key: o.toString(),
                    value: e[o].toString()
                };
                n.push(i);
            }
            return wx.getOpenDataContext().postMessage({
                method: "updateRankData",
                data: {
                    method_id: t,
                    kvDataList: n
                }
            }), this.methodIndex++, t;
        },
        getFriendRankData: function (e, t, n) {
            var o = "getFriendRankData" + this.methodIndex, i = ["avatarUrl", "nickName"];
            for (var a in i) e.indexOf(i[a]) < 0 && e.push(i[a].toString());
            return wx.getOpenDataContext().postMessage({
                method: "getFriendRankData",
                data: {
                    method_id: o,
                    keyList: e
                }
            }), this.methodCallDic[o] = {
                time: new Date().valueOf(),
                success_callback: t,
                fail_callback: n
            }, o;
        },
        getGroupRankData: function (e, t, n, o) {
            var i = "getFriendRankData" + this.methodIndex, a = ["avatarUrl", "nickName"];
            for (var r in a) e.indexOf(a[r]) < 0 && e.push(a[r].toString());
            return wx.getOpenDataContext().postMessage({
                method: "getGroupRankData",
                data: {
                    method_id: i,
                    shareTicket: t,
                    keyList: e
                }
            }), this.methodCallDic[i] = {
                time: new Date().valueOf(),
                success_callback: n,
                fail_callback: o
            }, i;
        }
    }
